//
//  JYBaseViewController.swift
//  WeiBoDemo
//
//  Created by 万佳阳 on 16/8/1.
//  Copyright © 2016年 JYWan. All rights reserved.
//

import UIKit

class JYBaseViewController: UITableViewController {
    // MARK:- 懒加载属性
    lazy var visitorView : JYVisitorView = JYVisitorView.visitorView()
    
    // MARK:- 定义变量
    var isLogin : Bool = JYUserAccountViewModel.shareInstance.isLogin
    
    //系统函数回调
    override func loadView() {
        
        //判断加载哪一个view
        isLogin ? super.loadView() : setupVisitorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
   
}

// MARK:- 设置UI界面
extension JYBaseViewController {
    ///设置访客视图
    private func setupVisitorView() {
        
        view = visitorView
        
        //监听访客视图中注册和登录的点击
        visitorView.registerBtn.addTarget(self, action: #selector(JYBaseViewController.registerBtnClick), forControlEvents: .TouchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(JYBaseViewController.loginBtnClick), forControlEvents: .TouchUpInside)
        
        //设置导航栏左右的item
        setupNavItem()
    }
    
    ///设置导航栏左右的item
    private func setupNavItem() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(JYBaseViewController.registerBtnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: #selector(JYBaseViewController.loginBtnClick))
    }
}

// MARK:- 事件监听
extension JYBaseViewController {
    @objc private func registerBtnClick() {
        print("registerBtnClick")
    }
    @objc private func loginBtnClick() {
        //创建授权控制器
        let oauthVc = JYOAuthViewController()
        
        //包装导航控制器
        let oauthNav = UINavigationController(rootViewController: oauthVc)
        
        //弹出控制器
        presentViewController(oauthNav, animated: true, completion: nil)
        
    }
}






